#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	struct student {
		string name;
		int chinese,math;
		int total;
	} aa[105];
	
	for (int i=0;i<n;i++)
	{
		cin>>aa[i].name;
		cin>>aa[i].chinese>>aa[i].math;
		aa[i].total=aa[i].chinese+aa[i].math;
	}
	
	for (int i=n-1;i>0;i--) 
		for (int j=0;j<i;j++) 
			if (aa[j].total<aa[j+1].total) 
				swap(aa[j],aa[j+1]);
	
	for (int i=0;i<n;i++) 
		cout<<aa[i].name<<' '<<aa[i].chinese<<' '<<aa[i].math<<' '<<aa[i].total<<endl;
	
	return 0;
}